<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <title>排刀</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../css/style.css">

</head>
<body>
<div>
    <ul class="layui-nav">
        <li class="layui-nav-item layui-this"><a href="/pd.html">排刀功能</a></li>
        <li class="layui-nav-item"><a href="/lineup.html">轴资料</a></li>
        <li class="layui-nav-item"><a href="/box.html">box资料</a></li>
        <li class="layui-nav-item"><a href="/param.html">参数设置</a></li>
    </ul>
</div>
<div>
    <ul class="layui-nav">
    </ul>
</div>
<div class="demoTable" style="margin-top: 20px;text-align: right;">
    名称：
    <div class="layui-inline">
        <input class="layui-input" name="id" id="demoReload" autocomplete="off">
    </div>
    <button class="layui-btn" id="search">搜索</button>
    <button class="layui-btn" id="calPossibleLineUp">计算可能的阵容</button>
    <button class="layui-btn" id="calPossible">计算可能的阵容组合</button>
    <button class="layui-btn" id="optimize">自动优化组合</button>
    <button class="layui-btn" id="calResult">计算排刀结果</button>
    <button class="layui-btn" id="downloadResult">下载排刀结果</button>
</div>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script src="./js/mainmenu.js" charset="utf-8"></script>
<script>
    layui.use(['table','jquery'], function(){
        var table = layui.table;
        var $ = layui.jquery;

        table.render({
            elem: '#test'
            ,url:'/pd/5.getUserSetMeal'
            ,title: '可选组合'
            ,headers:{ token: window.sessionStorage.getItem('token') }
            ,cols: [[
                {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, hide:true}
                ,{field:'memberNames', title:'会员名称', edit: 'text',  width:'15%'}
                ,{field:'score', title:'评分', edit: 'text',  width:'5%'}
                ,{field:'lineup1Detail', title:'第一刀', templet:'#lineup1Detail'}
                ,{field:'lineup2Detail', title:'第二刀', templet:'#lineup2Detail'}
                ,{field:'lineup3Detail', title:'第三刀', templet:'#lineup3Detail'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo',  width:'10%'}
            ]]
            ,id: 'testReload'
        });

        //监听工具条
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                if(!data.memberId){
                    layer.alert("只能搜索人之后，删除个人的组合阵容")
                    return;
                }
                $.ajax({
                    url:"/pd/5.subMemberCompose?memberId=" + data.memberId + "&lineupComposeId=" + data.id,
                    type: "POST",
                    datType: "JSON",
                    contentType: "application/json",
                    headers:{ token: window.sessionStorage.getItem('token') },
                    success:function(result){
                        if (result.code == 0) {
                            $('#search').click();
                        }else{
                            layer.alert("异常错误:"+result.message)
                        }
                    },
                    error: function () {
                        layer.alert("请求失败，请联系管理员")
                    }
                })
            }

        });


        $('#search').on('click', function(){
            var demoReload = $('#demoReload');
            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    userName:demoReload.val()
                }
            }, 'data');
        });
        $('#calPossible').on('click', function(){
            $.ajax({
                url:"/pd/4.calPossibleCompose",
                type: "POST",
                datType: "JSON",
                contentType: "application/json",
                headers:{ token: window.sessionStorage.getItem('token') },
                success:function(result){
                    if (result.code == 0) {
                        parent.location.reload()
                    }else{
                        layer.alert("异常错误:"+result.message)
                    }
                },
                error: function () {
                    layer.alert("请求失败，请联系管理员")
                }
            })
        });

        $('#calPossibleLineUp').on('click', function(){
            $.ajax({
                url:"/pd/3.calPossibleLineUp",
                type: "POST",
                datType: "JSON",
                contentType: "application/json",
                headers:{ token: window.sessionStorage.getItem('token') },
                success:function(result){
                    if (result.code == 0) {
                        parent.location.reload()
                    }else{
                        layer.alert("异常错误:"+result.message)
                    }
                },
                error: function () {
                    layer.alert("请求失败，请联系管理员")
                }
            })
        });

        $('#optimize').on('click', function(){
            $.ajax({
                // url:"/pd/5.optimizePossibleCompose?composeNum=5&difComposeRepeat=2",
                url:"/pd/5.optimizePossibleCompose",
                type: "POST",
                datType: "JSON",
                contentType: "application/json",
                headers:{ token: window.sessionStorage.getItem('token') },
                success:function(result){
                    if (result.code == 0) {
                        parent.location.reload()
                    }else{
                        layer.alert("异常错误:"+result.message)
                    }
                },
                error: function () {
                    layer.alert("请求失败，请联系管理员")
                }
            })
        });
        $('#calResult').on('click', function(){
            layui.layer.open({
                type: 2,
                title: '输入目标',
                shadeClose: true,
                shade: 0.8,
                area: ['600px', '80%'],
                content: '/target.html' //iframe的url
            });
        });

        $('#downloadResult').on('click', function(){
            window.location.href="/pd/7.downloadResult?token="+window.sessionStorage.getItem('token');
        });
    });
</script>

<script type="text/html" id="lineup1Detail">
    {{d.lineup1Detail.bossNo}}王:{{d.lineup1Detail.damage}}w:{{d.lineup1Detail.lineupCardNames}}
</script>

<script type="text/html" id="lineup2Detail">
    {{d.lineup2Detail.bossNo}}王:{{d.lineup2Detail.damage}}w:{{d.lineup2Detail.lineupCardNames}}
</script>

<script type="text/html" id="lineup3Detail">
    {{d.lineup3Detail.bossNo}}王:{{d.lineup3Detail.damage}}w:{{d.lineup3Detail.lineupCardNames}}
</script>

</body>
</html>